define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/comment/index' + location.search,
                    add_url: 'order/comment/add',
                    edit_url: 'order/comment/edit',
                    del_url: 'order/comment/del',
                    multi_url: 'order/comment/multi',
                    import_url: 'order/comment/import',
                    table: 'order_comment',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('订单ID')},
                        {field: 'dou_code', title: __('抖音券'), operate: 'LIKE'},
                        {field: 'mt_code', title: __('美团券'), operate: 'LIKE'},
                        {field: 'status', title: __('状态'), searchList: {"verifying":__('待审核'),"undo":__('未使用'),"done":__('已使用')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'hour', title: __('免费时长'), operate: 'LIKE'},
                        {field: 'valid_time', title: __('有效时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'cover', title: __('好评图'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'user.mobile', title: __('用户'),operate: 'LIKE'},
                        {field: 'shop.name', title: __('适用店铺'),operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            $(document).on("click", ".btn-batch", function () {
                var ids = Table.api.selectedids(table);
                if(ids.length > 0){
                    Fast.api.open('order/comment/batch?ids='+ids, '批量操作');
                }else{
                    alert('请选择再操作');
                }
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        batch:function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
